I am trying to create a script that will create users in our account, so I donât have to create massive number of accounts manually. Currently, I have a list of almost 200 that need to be created. I can successfully GET our user account info using the following, and it works just fine:
$APIKey=âToken token=[REMOVED]â
$URI0 = âURLâ
$URI1 = âhttps://api.pagerduty.com/users?offset=100&limit=200â
$PDoutput1=Invoke-RestMethod -Method Get -Uri $URI0 -Header @{âAuthorizationâ=$APIKey; âAcceptâ = "application/vnd.pagerduty+json;version=2â}
$PDoutput2=Invoke-RestMethod -Method Get -Uri $URI1 -Header @{âAuthorizationâ=$APIKey; âAcceptâ = "application/vnd.pagerduty+json;version=2â}
Now to CREATE users, I put this together:
$APIKey= âToken token=[REMOVED]â
$URI0 = âURL (said I can only have 2 links in a post)â
#User Info
$name = ââ
$email = ââ
#Role name in PD and what they mean
#Manager = user
#Responder = limited_user
#Observer = observer
#Global Admin = admin
#Account Owner = owner
$role = âuserâ
$header = @"
{
"Authorization"= "$APIKey"
"Accept" = "application/vnd.pagerduty+json;version=2â
"From" = "<my email address>"
"user": {
"type": "user",
"name": "$name",
"email": "$email",
"role": "$role"
}
}
"@
Invoke-RestMethod -Method Post -Uri $URI0 -Headers $header
And the resulting error:
Invoke-RestMethod : Cannot bind parameter âHeadersâ. Cannot convert the "{
âAuthorizationâ= âToken token=[Removed]â
âAcceptâ = "application/vnd.pagerduty+json;version=2â
âFromâ = "mcrane@proofpoint.com"
âuserâ: {
âtypeâ: âuserâ,
ânameâ: ââ,
âemailâ: âEmail addressâ,
âroleâ: âuserâ
}
}" value of type âSystem.Stringâ to type âSystem.Collections.IDictionaryâ.
At line:36 char:52
- Invoke-RestMethod -Method Post -Uri $URI0 -Headers $header
-
~~~~~~~- CategoryInfo : InvalidArgument: (
[Invoke-RestMethod], ParameterBindingException - FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
- CategoryInfo : InvalidArgument: (